package org.geometerplus.fbreader.book;


import com.example.administrator.fangbook.dataLibrary.book.ShelfItemBook;
import com.example.administrator.fangbook.read.bean.Chapter;

import org.geometerplus.fbreader.formats.BookReadingException;
import org.geometerplus.fbreader.formats.FormatPlugin;
import org.geometerplus.fbreader.formats.IChapterReadBook;
import org.geometerplus.fbreader.formats.m17k.MTxtNovelReader;
import org.geometerplus.zlibrary.core.filesystem.ZL17KPlainTxtFile;
import org.geometerplus.zlibrary.text.view.ZLTextPosition;

public class M17kPlainTxtBook extends ReadBook implements IChapterReadBook {


	private ShelfItemBook book;
	
	public MTxtNovelReader getReader() {
		return (MTxtNovelReader) myBookReader;
	}
	public void setReader(MTxtNovelReader reader)
	{
		myBookReader = reader;
	}
    public M17kPlainTxtBook(ZL17KPlainTxtFile file, FormatPlugin plugin) throws BookReadingException {
		super(file, plugin);
		setTitle(file.getBookName());
		book = file.getShelfBook();
	}
	
	public M17kPlainTxtBook(long id, ZL17KPlainTxtFile file, String title, String encoding, String language)
	{
		super(id, file, title, encoding, language);
		book = file.getShelfBook();
	}
	

	public void storePosition(ZLTextPosition position) {
        MTxtNovelReader reader = (MTxtNovelReader) myBookReader;
		Chapter readingChapter = reader != null ? reader.getReadingChapter() : null;
		if(position != null && readingChapter != null)
		{
			position.setTag(readingChapter.getId());
		}
		super.storePosition(position);
	}
	public String getBookId()
	{
		return ((ZL17KPlainTxtFile)File).getBookId();
	}
	public String getChapterId()
	{
		return ((ZL17KPlainTxtFile)File).getChapterId();
	}
	
	public ShelfItemBook getShelfBook()
	{
		return book;
	}
	
}
